package com.bustle.user.proxy;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import com.bustle.commons.XmlParser;
import com.bustle.commons.data.dao.Dao;
import com.bustle.commons.data.dao.DaoProxy;
import com.bustle.commons.http.RestDtoDaoProxy;
import com.bustle.commons.http.TypeToXmlHttpConverter;
import com.bustle.user.dto.user.UserDto;
import com.bustle.user.dto.user.UserDtoDaoWebService.UserDtoList;
import com.bustle.user.dto.user.UserDtoMapper;

@Local
public interface UserDtoDaoProxy extends Dao<Integer, UserDto>
{
  @Stateless
  public class DefaultUserDtoDaoProxy extends DaoProxy<Integer, UserDto, Dao<Integer, UserDto>> implements UserDtoDaoProxy
  {
    @PostConstruct
    public void postBuild()
    {
      dao = new RestDtoDaoProxy<Integer, UserDto>("localhost", 8080, "user", new XmlParser(), new TypeToXmlHttpConverter<>(UserDto.class), UserDto.class, dtoMapper)
        {
          @Override
          protected List<UserDto> retrieveAllFrom(String aResult)
          {
            return parser.parse(UserDtoList.class, aResult).getUser();
          }
        };
    }

    @EJB
    protected UserDtoMapper dtoMapper;
  }
}
